"""
网络请求工具类
"""
import random


class HttpUtils:
    def get_user_agent(self):
        """
        随机获取user-agent
        :return:
        """
        user_agent_file = "../setting/user_agent.txt"
        user_agent_list = list()
        try:
            f = open(user_agent_file, "r")
            user_agent_list = f.read().splitlines()
        except IOError:
            print(f"文件读取失败，文件目录：{user_agent_file}")
        finally:
            f.close();
        user_agent = user_agent_list[random.randint(0, len(user_agent_list) - 1)]
        return user_agent

    def get_proxy(self):
        """
        获取代理IP
        :return:
        """


# 模块化
_inst = HttpUtils()
get_user_agent = _inst.get_user_agent()
